/**
 * 
 */
package com.rapsoft.daoimpl;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.criterion.Criterion;

import com.rapsoft.dao.BaseDAO;

/**
 * @author Aravind
 *
 */
public  class BaseDaoImpl <Entity, ID extends Serializable> implements BaseDAO<Entity, ID>  {
	
	 private Class<Entity> persistentClass;
	 private Session session;
	 private static SessionFactory factory; 
	
	public BaseDaoImpl() {
        this.persistentClass = (Class<Entity>) ((ParameterizedType) getClass()
                .getGenericSuperclass()).getActualTypeArguments()[0];
    }

	@Override
	public Entity findById(ID id, boolean lock) {
		
		return null;
	}

	@Override
	public List<Entity> findAll() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ID save(Entity entity) {
		session = getSession();
		Transaction transaction =session.beginTransaction();
				
		 Long transId = (Long) session.save(entity);
		  transaction.commit();
		  return (ID) transId;
	}

	@Override
	public void update(Entity entity) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void delete(Entity entity) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void deleteById(ID id) {
		// TODO Auto-generated method stub
		
	}

	public Session getSession(){
		return session = HibernateUtil.getSessionFactory().openSession();
	}

}
